<template>
  <div>
    <el-table :data="goodslist" border style="width: 100%">
      <el-table-column prop="id" label="用户编号"> </el-table-column>
      <el-table-column prop="goodsname" label="商品名称"> </el-table-column>
      <el-table-column prop="price" label="商品价格"> </el-table-column>
      <el-table-column prop="market_price" label="市场价格"> </el-table-column>
      <el-table-column prop="img" label="图片">
        <template slot-scope="scope">
          <div>
            <img :src="$pre + scope.row.img" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="是否新品">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if="scope.row.isnew == 1">是</el-button>
            <el-button type="warning" v-else>否</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="ishot" label="是否热卖">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if="scope.row.ishot == 1">是</el-button>
            <el-button type="warning" v-else>否</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if="scope.row.status == 1">启用</el-button>
            <el-button type="warning" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="success" @click="bianji(scope.row.id)"
              >编辑</el-button
            >
            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="goodscount"
      :page-size="goodssize"
      @current-change="change"
    >
    </el-pagination>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { goodsdelete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../util/alert";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      reqgoodslist: "goods/reqchangelist",
      reqgoodscount: "goods/reqchangecount",
      reqgoodspage: "goods/reqchangepage",
    }),
    // 页数发送改变
    change(num) {
    this.reqgoodspage(num)
    },
    // 点击删除
    del(id) {
      goodsdelete({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          // 刷新列表
          this.reqgoodslist();
          // 刷新总个数
          this.reqgoodscount();
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    // 点击编辑
    bianji(id) {
      this.$emit("bianji", id);
    },
  },
  computed: {
    ...mapGetters({
      goodslist: "goods/list",
      goodscount:'goods/count',
      goodssize:'goods/size',
    }),
  },
  mounted() {
    // 每一次进来都将状态层的当前页码数变成1
    this.reqgoodspage(1);
    this.reqgoodscount()
  },
};
</script>

<style lang="less" scoped>
img {
  width: 100px;
  height: 100px;
}
</style>